package com.hhxy.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author ghp
 * @date 2022/9/13
 */
@WebServlet("/acceptServlet")
public class AcceptServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1、获取ServletContext域对象的数据
        ServletContext context = this.getServletContext();
         String data = (String) context.getAttribute("data");
        //2、将数据打印到网页上进行展示
        PrintWriter pw = response.getWriter();
        pw.write(data);
    }
}